import React, {Component } from 'react';
import ClickCounter from './ClickCounter'
import logo from './logo.svg';
import './App.css';

class App extends Component {

  constructor(props){
    super(props);
    this.onCountChanged = this.onCountChanged.bind(this);
    this.state = {sum:0};
  }

  onCountChanged(current,next){
    this.setState({sum:this.state.sum + (next-current)});
  }

  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>

        <ClickCounter initValue={123} buttonText="Hello ABC1" onUpdate={this.onCountChanged}/>
        <ClickCounter initValue={2} buttonText="Button2" onUpdate={this.onCountChanged}/>
        <ClickCounter initValue={3} buttonText="Text" onUpdate={this.onCountChanged}/>
        <ClickCounter  onUpdate={this.onCountChanged}/>


        sum value:{this.state.sum}
      </div>
    );
  }
}

export default App;
